﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace coliseu.BussinessLayer
{
    public class RotinaBL
    {
         private coliseuEntities cEntities;

         public RotinaBL()
        {
            cEntities = new coliseuEntities(Properties.Settings.Default.conn_coliseu);
        }

        public List<rotina> selecionar()
        {
            return (from x in cEntities.rotina orderby x.hora select x).ToList();
        }

        public List<rotina> selecionar(DateTime ini, DateTime fim)
        {
            return (from x in cEntities.rotina where x.data >= ini && x.data <= fim orderby x.hora select x).ToList();
        }

        public void salvar(rotina b, string tipo)
        {

            if (tipo == "insert")
            {
                cEntities.AddTorotina(b);
            }
            else
            {
                cEntities.rotina.ApplyCurrentValues(b);
            }
            cEntities.SaveChanges();
        }

        public void excluir(rotina b)
        {
            cEntities.rotina.DeleteObject(b);
            cEntities.SaveChanges();
        }
    }
}
